/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.mts.client.core.modal;

import com.google.common.collect.Lists;
import com.intelligent.mts.core.dto.AttributeDto;
import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * Created by cherry on 2016/7/22.
 */
public class ProcessDataModal extends AbstractTableModel {

    private String columns[];

    private List<AttributeDto>data;

    public ProcessDataModal (String columns []) {
        this.columns = columns;
    }

    @Override
    public int getRowCount() {
        if (data == null) {
            return 0;
        }
        else {
            return data.size();
        }
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public String getColumnName(int column) {
        return columns[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {

        AttributeDto attributeDto = data.get(rowIndex);
        if (columnIndex == 0) {
            return attributeDto.getStationId();
        } else if (columnIndex == 1) {
            return attributeDto.getOderId();
        }
        return attributeDto.getAttributeValue();
    }

    public void setData(List<AttributeDto> data) {
        if (data == null) {
            data = Lists.newArrayList();
        }

        this.data = data;
        fireTableDataChanged();
    }
}
